package com.zykj.evaluation.ui

import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.zykj.evaluation.viewmodel.TabEntity

@Composable
fun TabList(
    tabList: List<TabEntity>,
    modifier: Modifier = Modifier,
    current: TabEntity,
    onTabSelected: (TabEntity) -> Unit
) {
    LazyColumn(modifier = modifier) {
        items(tabList) { item ->
            TabItem(
                tabItemEntity = item,
                current == item,
                onTabSelected = onTabSelected
            )
            Spacer(modifier = Modifier.height(15.dp))
        }
    }
}

@Composable
fun TabItem(
    tabItemEntity: TabEntity,
    isSelected: Boolean,
    onTabSelected: (TabEntity) -> Unit
) {
    Box(
        modifier = Modifier
            .clickable {
                onTabSelected.invoke(tabItemEntity)
            }
            .padding(5.dp),
        contentAlignment = Alignment.Center
    ) {
        Column(
            modifier = Modifier
                .align(
                    alignment =
                    Alignment.Center
                )
                .fillMaxSize(),
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            Image(
                painter = painterResource(id = if (isSelected) tabItemEntity.imageSelected else tabItemEntity.imageUnselected),
                contentDescription = null,
                modifier = Modifier.size(36.dp, 36.dp)
            )
            Text(
                text = stringResource(id = tabItemEntity.label),
                fontSize = 11.sp,
                textAlign = TextAlign.Center,
                style = MaterialTheme.typography.bodySmall.copy(color = Color(0xFF555555))
            )
        }
//        if (tabItemEntity.unreadCount > 0) {
//            val strCount =
//                if (tabItemEntity.unreadCount > 99) "99+" else tabItemEntity.unreadCount.toString()
//            Box(
//                modifier = Modifier
//                    .size(15.dp, 15.dp)
//                    .clip(CircleShape)
//                    .background(color = Color(0xfffb7768))
//                    .align(Alignment.TopEnd),
//                contentAlignment = Alignment.Center
//            ) {
//                Text(
//                    text = strCount,
//                    fontSize = 8.sp,
//                    color = Color.White,
//                    textAlign = TextAlign.Center
//                )
//            }
//        }
    }
}
